﻿using CommunityToolkit.Mvvm.ComponentModel;
using GameView.Comment;
using GameView.Models;
using GameView.Services.Dtos.Persons;

namespace GameView.Services.Comment
{
    public partial class UserService : ObservableObject
    {
        private string baseUrl = "";

        public UserService()
        {
            baseUrl = APIHelper.User;
        }

        public async Task<ApiResponse<PagedList<PersonnelOutDto>>> GetByPage(PersonnelQueryDto queryDto)
        {
            var res = await $"{APIHelper.User}/page".PostAsync<PagedList<PersonnelOutDto>, PersonnelQueryDto>(queryDto);
            return res;
        }

        public async Task<ApiResponse<bool>> AddNew(PersonnelAddDto queryDto)
        {
            var res = await $"{APIHelper.User}".AddNewAsync<PersonnelAddDto>(queryDto);
            return res;
        }

        public async Task<ApiResponse<PersonnelSimple>> Update(PersonnelUpdateDto queryDto)
        {
            var res = await $"{APIHelper.User}/edit".PutAsync<PersonnelSimple, PersonnelUpdateDto>(queryDto);
            return res;
        }

        public async Task<ApiResponse<List<PersonnelSimple>>> GetChildrensAsync(int id)
        {
            var res = await $"{APIHelper.User}/childrens/{id}".GetAsync<List<PersonnelSimple>, object>();
            return res;
        }

        public async Task<ApiResponse<int>> GetABCAsync(int id)
        {
            var res = await $"{APIHelper.User}/abc/{id}".GetAsync<int, object>();
            return res;
        }

        public async Task<ApiResponse<int>> Delete(List<int> queryDto)
        {
            var res = await $"{APIHelper.User}/batch-delete".DeleteData<List<int>>(queryDto);
            return res;
        }

        public async Task<ApiResponse<string>> ResetPassword(int id)
        {
            var res = await $"{APIHelper.User}/reset-passwords/{id}".GetAsync<string, object>();
            return res;
        }

        public async Task<ApiResponse<bool>> ResetPassword(ResetPasswordEntity id)
        {
            var res = await $"{APIHelper.User}/reset-passwords".PostAsync<bool, ResetPasswordEntity>(id);
            return res;
        }

        public async Task<ApiResponse<List<PersonnelSimple>>> GetMersByprojectNameAsync(string pname)
        {
            var res = await $"{APIHelper.User}/person-names-by-project-name/{pname}".GetAsync<List<PersonnelSimple>, object>();
            return res;
        }

        public async Task<ApiResponse<List<PersonnelSimple>>> GetAllByRoleAsync()
        {
            var res = await $"{APIHelper.User}/all-by-role".GetAsync<List<PersonnelSimple>, object>();
            return res;
        }

        public async Task<ApiResponse<List<ProjectPersonRelationEntity>>> PPGetAllAsync()
        {
            var res = await $"{APIHelper.User}/all-pp".GetAsync<List<ProjectPersonRelationEntity>, object>();
            return res;
        }

        public async Task<ApiResponse<int>> PPBindingAsync(List<ProjectPersonAddDto> dto)
        {
            var res = await $"{APIHelper.User}/binding".PostAsync<int, List<ProjectPersonAddDto>>(dto);
            return res;
        }

        public async Task<ApiResponse<int>> PPDeleteAsync(List<int> ids)
        {
            var res = await $"{APIHelper.User}/un-binding".DeleteData<List<int>>(ids);
            return res;
        }
    }
}